<?php

namespace App\Libs\Company\SheetTemplateHandler\Report;

use App\Services\DictService;

class BaseEmployment extends AbstractTemplate
{
    public $dataStartRow = 3;

    protected $dictCategoryCode;

    public function generateReport()
    {
        if (empty($this->dictCategoryCode)) {
            throw new \Exception('必须设置 $dictCategoryCode');
        }
        $this->renderHeader();
        $this->output['sheets']['sheet-01']['cellData']['0']['0'] = $this->createTitleCell('日喀则市' . $this->getDistrictName($this->subTask->district_id) . "{$this->subTask->task->year}年{$this->subTask->task->key}月\r{$this->template->name}");

        $dicts = DictService::getList($this->dictCategoryCode, $this->subTask->district_id);
        $sn = 1;
        foreach ($dicts as $value) {
            $this->output['sheets']['sheet-01']['cellData'][$this->dataEndRow] = [
                ['v' => $sn++, 's' => 'CENTER'],
                ['v' => $value->dict_code, 's' => 'CENTER'],
                ['vt' => 1, 't' => 2], //0-需要填写无需验证 1-整数 2-2位小数
                ['vt' => 1, 't' => 2],
                ['vt' => 2, 't' => 2],
            ];

            $this->output['sheets']['sheet-01']['rowData'][$this->dataEndRow]['h'] = 40;
            $this->dataEndRow++;
        }

        $this->dataEndRow--;
        $this->renderFooter();
        return $this->output;
    }
}
